public class LengthOfLastWord {
    public static int lengthOfLastWord(String s) {
        char[] chars = s.toCharArray();
        int len =0;
        if (chars.length==1&&chars[0]!=' '){
            return 1;
        }

        for (int i=chars[chars.length-1];i>=0;i--){
            if (chars[i]!=' '){
                len++;
            } else if (len!=0)
            {
                return len;

            }


        }

        return len;
    }

    public static void main(String[] args) {

    }
}

